//
// Templet.h
//
// $Id: //base/include/Templet.h
//
// Library: base
// Package: base
// Module : Templet
// Author :	Jelin,doitsjz@163.com
// Date	  :	10/30/2012
// 
// Definition of the Templet class.
//
// Copyright (c) 2012-2012, iGuard.
//

#include "BaseHTTPClientSession.h"
#include <sstream>
#include <map>

//BaseHTTPClientSession::BaseHTTPClientSession(string &strURL):m_strURL(strURL)
//{
//}
BaseHTTPClientSession::BaseHTTPClientSession()
{
}
BaseHTTPClientSession::~BaseHTTPClientSession()
{

}

int BaseHTTPClientSession::handleMessage(BaseHTTPRequest& request)
{
	return 0;
}
int BaseHTTPClientSession::handleMessage(BaseHTTPResponse& reply)
{
	OnReply(reply.getStatus(),reply);

	return true;
}
int BaseHTTPClientSession::makeRequest(const string& method,string& url,string& body,string& req)
{
	BaseHTTPRequest request(method, url);
	
	if (!body.empty())
	{
		request.setContentType("text/xml");
		request.setContentBody(body);
		request.setContentLength(body.length());
	}

	std::ostringstream ostr;	
	request.write(ostr);
	req = ostr.str();

	return 0;
}

int BaseHTTPClientSession::makeGetRequest(string& url,string& body,string& req)
{
	return makeRequest(HTTPRequest::HTTP_GET,url,body,req);
}
int BaseHTTPClientSession::makePostRequest(string& url,string& body,string& req)
{
	return makeRequest(HTTPRequest::HTTP_POST,url,body,req);
}
int BaseHTTPClientSession::makePutRequest(string& url,string& body,string& req)
{
	return makeRequest(HTTPRequest::HTTP_PUT,url,body,req);
}
int BaseHTTPClientSession::makeDeleteRequest(string& url,string& body,string& req)
{
	return makeRequest(HTTPRequest::HTTP_DELETE,url,body,req);
}
